package com.aaa.docter.service.Impl;

import com.aaa.docter.dao.HospitalDao;
import com.aaa.docter.service.HospitalService;
import com.aaa.docter.vo.HosVo;
import com.aaa.entity.HisPatient;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalDao hospitalDao;

    @Override
    public Result<IPage<HisPatient>> getByPage(Integer currentPage, Integer pageSize, HosVo hosVo) {
        System.out.println("idcard+++++++++++"+hosVo);
        IPage<HisPatient> page = new Page<>(currentPage, pageSize);
        QueryWrapper<HisPatient> wrapper = new QueryWrapper<>();
//        判断里面是否由内容，模糊差
        if (StringUtils.hasText(hosVo.getName())){
            wrapper.eq("name",hosVo.getName());
        }
        if (StringUtils.hasText(hosVo.getPhone())){
            wrapper.eq("phone",hosVo.getPhone());
        }
        if (StringUtils.hasText(hosVo.getIdCard())){
            wrapper.eq("id_card",hosVo.getIdCard());
        }

      IPage<HisPatient> page1= hospitalDao.selectPage(page,wrapper);

        return new Result<IPage<HisPatient>>(2000,"患者查询成功",page1);
    }

    @Override
    public Result<HisPatient> getAll(String patientId) {
        HisPatient hisPatient= hospitalDao.getAll(patientId);
        return new Result<>(2000,"查询患者信息成功",hisPatient);
    }
}
